#include <bits/stdc++.h>
using namespace std;
#define lowbit(x) (x & -x)
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
void solve()
{
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }

    int low = 0, high = *max_element(a.begin(), a.end());
    int ans = high;

    while (low <= high)
    {
        int mid = (low + high) / 2;
        bool feasible = false;

        int must_B = 0;
        for (int i = 0; i < n; ++i)
        {
            if (s[i] == 'B' && a[i] > mid)
            {
                must_B++;
            }
        }

        if (must_B == 0)
        {
            feasible = true;
        }
        else
        {
            int segments = 0;
            bool in_segment = false;
            for (int i = 0; i < n; ++i)
            {
                if (s[i] == 'B' && a[i] > mid)
                {
                    if (!in_segment)
                    {
                        segments++;
                        in_segment = true;
                    }
                }
                else if (s[i] == 'R' && a[i] > mid)
                {
                    in_segment = false;
                }
            }
            if (segments <= k)
            {
                feasible = true;
            }
        }

        if (feasible)
        {
            ans = mid;
            high = mid - 1;
        }
        else
        {
            low = mid + 1;
        }
    }

    cout << ans << '\n';
}
signed main()
{
    int tt = 1;
    cin >> tt;
    while (tt--)
        solve();
    return 0;
}
